package com.hngy.xpq.dianming;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.Random;

public class MainActivity2 extends AppCompatActivity implements View.OnClickListener {

    TextView text;
    Button button1,button2,button3,button4;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        button1 = findViewById(R.id.button_03);
        button2 = findViewById(R.id.button_04);
        button3 = findViewById(R.id.button_05);
        button4 = findViewById(R.id.button_06);
        text = findViewById(R.id.text_03);

        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);
        button4.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        String[] indexXingYun1 = getResources().getStringArray(R.array.yy19_1);
        String[] indexXingYun2 = getResources().getStringArray(R.array.yy19_2);
        String[] indexXingYun3 = getResources().getStringArray(R.array.XingYunbj);
        Random XingYun = new Random();
        int kelang = XingYun.nextInt(39) + 1;
        int banji = XingYun.nextInt(2) + 1;
        String a = String.valueOf(kelang);
        switch (v.getId()){
            case R.id.button_03:
                text.setText("学号：" + a + '\n' + "  名字:  " + indexXingYun1[kelang]);
                break;
            case R.id.button_04:
                text.setText("学号：" + a + '\n' + "  名字:" + indexXingYun2[kelang]);
                break;
            case R.id.button_05:
                if( banji == 1 ){
                    text.setText(indexXingYun3[banji] + '\n' + "  学号：" + a + '\n' + "  名字:  " + indexXingYun1[kelang]);
                } else{
                    text.setText(indexXingYun3[banji] + '\n' +  "  学号：" + a + '\n' + "  名字:  " + indexXingYun2[kelang]);
                }
                break;
            case R.id.button_06:
                Intent intent = new Intent(MainActivity2.this,MainActivity_lord.class);
                startActivity(intent);
                break;
        }
    }
}